package com.fnd.med.zsms.service.impl;

import javax.inject.Inject;
import javax.inject.Named;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.fnd.med.utils.BaseDao;
import com.fnd.med.zsms.bean.User;
import com.fnd.med.zsms.service.UserService;


@Named("userService")
public class UserServiceImpl implements UserService {
	
	
	@Inject
	private BaseDao baseDao;
	
	@Override
	public User getUser(String username, String password) {
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(User.class);
		detachedCriteria.add(Restrictions.eq("username", username));
		detachedCriteria.add(Restrictions.eq("password", password));
		return baseDao.getUnique(detachedCriteria);
	}
	
	@Override
	public User changePassword(User user, String newPassword) {
		User user1 = baseDao.get(User.class, user.getSeq());
		user1.setPassword(newPassword);
		return user1;
	}
}
